package com.example.huhaichao.fmusic.model;

import android.content.Context;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by huhaichao on 2017/10/20.
 * 需要上下文
 */

public class PropertyBean {
    private Context context;
    private String theme;

    public PropertyBean(Context context) {
        this.context = context;
    }

    public String loadTheme() {
        Properties properties = new Properties();
        try {
            FileInputStream in = context.openFileInput("config.cfg");
            properties.load(in);
            theme = properties.getProperty("theme").toString();
            return theme;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "0";
    }

    public boolean saveTheme(String theme) {
        Properties properties = new Properties();
        properties.put("theme", theme);
        try {
            FileOutputStream out = context.openFileOutput("config.cfg", context.MODE_PRIVATE);
            properties.store(out, "");
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

}
